import os.path
import time
import uuid

from tests.ry_park_service.parking_tools import *


class ParkEnter:

    # =====================车辆进场=====================

    #查询进场车辆信息
    def queryCarEnter(self,env,plate=""):

        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/queryCarEnter"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": login_token(env)}
        dict = {
            "parkingGateId": getconf(env,"parkingGateId_in"),
            "parkingSentryBoxId": getconf(env,"parkingSentryBoxId"),
            "plate": plate,
            "serial":str(uuid.uuid1())
        }
        return requests.post(url, headers=headers, json=dict).json()

    # 进场记录上报
    def reportEnter(self, env, plate="",release_type=1):
        base_url = getconf(env, "parking_service_url")
        url = base_url + "/v1/park/enter"
        headers = {"token": login_token(env)}
        dict = {
            "parkingGateId": getconf(env, "parkingGateId_in"),
            "parkingSentryBoxId": getconf(env, "parkingSentryBoxId"),
            "plate": plate,
            "carColor":"White",
            "plateColor":"Blue",
            "releaseType":release_type,  #1-自动放行；MANUAL：2-人工开闸；REGISTER：10-补录进场
            "serial":str(uuid.uuid1())
        }
        img_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))), 'img')
        files = {'file':('park.jpg',open(os.path.join(img_path,'park.jpg'),'rb'),'img/jpg')}
        return requests.post(url=url,headers=headers,data=dict, files=files).json()

if __name__ == '__main__':
    #获取存放图片的绝对路径
    # docs_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img\park.jpg')
    # print(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
    aa = time.localtime(time.time() - 86400 * 1)[0:3]
    aa = time.localtime(time.time() - 86400 * 1)
    print(time.time() - 86400 * 1)

    print(uuid.uuid1())